//
//  CSGXHeadView.m
//  CarSalesMS_GCX
//
//  Created by Tony on 2016/10/21.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSGXHeadView.h"
#import "CSGXHeadModel.h"

@interface CSGXHeadView ()

//@property (nonatomic, strong) CSGXHeadModel * headModel;

@property (nonatomic, strong) UIImageView * ivwIcon;
@property (nonatomic, strong) UILabel * lblName;
@property (nonatomic, strong) UILabel * lblNameType;
@property (nonatomic, strong) UIView * lineView;
@property (nonatomic, strong) UILabel * lblOtherInfo;

@end

@implementation CSGXHeadView

- (void)setupUI {
    //
    self.backgroundColor = [UIColor gx_colorWithRed:94 green:109 blue:129];
    //
    [self addSubview:self.ivwIcon];
    [self addSubview:self.lblName];
    [self addSubview:self.lblNameType];
    [self addSubview:self.lineView];
    [self addSubview:self.lblOtherInfo];
    
//    UIImage * img = [UIImage imageNamed:@"icon"];
//    NSLog(@"%@", img);
//    self.ivwIcon.backgroundColor = [UIColor orangeColor];
//    self.ivwIcon.contentMode = UIViewContentModeScaleAspectFit;
//    self.ivwIcon.clipsToBounds = YES;
//    self.ivwIcon.image = img;
    
    //
    [self.ivwIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(self).offset(8);
        make.size.mas_offset(CGSizeMake(100, 100));
    }];
    
//    self.lblName.text = @"客户姓名";
    
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(8);
        make.leading.equalTo(self.ivwIcon.mas_trailing).offset(8);
    }];
    
    [self.lblNameType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-8);
        make.bottom.equalTo(_lblName);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lblName.mas_bottom).offset(8);
        make.leading.equalTo(_lblName);
        make.trailing.equalTo(self).offset(-8);
        make.height.offset(1);
    }];
    
    [self.lblOtherInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_lblName);
        make.top.equalTo(_lineView.mas_bottom).offset(8);
    }];
}

//+ (instancetype)headViewWithHeadModel:(CSGXHeadModel *)headModel {
//    /*
//     1. instantiate data
//     2. load data
//     3. dispatch data
//     */
//    
//    CSGXHeadView * headView = [[CSGXHeadView alloc] init];
//    
//    headView.headModel = headModel;
//    
//    headView.ivwIcon.image = headModel.iconImage;
//    headView.lblName.text = headModel.name;
//    headView.lblNameType.text = headModel.nameType;
//    headView.lblOtherInfo.text = headModel.otherInfo;
//    
//    return headView;
//}



#pragma mark - lazy

- (UIImageView *)ivwIcon {
    if (!_ivwIcon) {
        _ivwIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon"]];
    }
    return _ivwIcon;
}


- (UILabel *)lblName {
    if (!_lblName) {
        _lblName = [UILabel gx_labelWithText:@"" fontSize:18 color:[UIColor whiteColor]];
    }
    return _lblName;
}


- (UILabel *)lblNameType {
    if (!_lblNameType) {
        _lblNameType = [UILabel gx_labelWithText:@"" fontSize:13 color:[UIColor whiteColor]];
    }
    return _lblNameType;
}


- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor whiteColor];
    }
    return _lineView;
}


- (UILabel *)lblOtherInfo {
    if (!_lblOtherInfo) {
        _lblOtherInfo = [UILabel gx_labelWithText:@"" fontSize:15 color:[UIColor whiteColor]];
    }
    return _lblOtherInfo;
}

- (void)setHeadModel:(CSGXHeadModel *)headModel {
    _headModel = headModel;
    
    self.ivwIcon.image = headModel.iconImage;
    self.lblName.text = headModel.name;
    self.lblNameType.text = headModel.nameType;
    self.lblOtherInfo.text = headModel.otherInfo;
}


@end
